package leetcode_core.leetcode_4;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2022年11月11日 8:04
 */
public class HalvesAreAlike {
    public boolean halvesAreAlike(String s) {
        int length = s.length();
        int a = length/2;
        String target = "aeiouAEI";
        Map<Character,Integer> targetMap = new HashMap<>();
        for(int i = 0;i<target.length();i++){
            targetMap.put(target.charAt(i),1);
        }
        int aCnt = 0;
        for(int i = 0;i<=a-1;i++){
            if(targetMap.get(s.charAt(i)) != null){
                aCnt++;
            }
        }
        int bCnt = 0;
        for(int i = a;i<length;i++){
            if(targetMap.get(s.charAt(i)) != null){
                bCnt++;
            }
        }
        if(aCnt == bCnt){
            return true;
        }
        return false;
    }

    @Test
    public void test(){
        System.out.println(halvesAreAlike("textbook"));
        System.out.println(halvesAreAlike("book"));
        System.out.println(halvesAreAlike("Uo"));
    }


}
